﻿using System;
using System.Linq;
using MartinRL.ProjectEuler.Sequences;

namespace MartinRL.ProjectEuler
{
    /// <summary>
    /// http://projecteuler.net/index.php?section=problems&id=3
    /// </summary>
    public static class Problem003
    {
         public static long FindTheLargestPrimeFactorOf600851475143()
         {
             const long term = 600851475143;

             return LongSequence.NewDecrementingSequence()
                 .Start(term.CalculateMaxFactor())
                 .Where(t => t.IsPrime())
                 .First(t => term.IsEvenlyDivisibleBy(t));
         }
    }
}